home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11633 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: jitter.larc.nasa.gov!lance
  2. From: lance@jitter.larc.nasa.gov ()
  3. Newsgroups: comp.lang.c++
  4. Subject: RE: Explicit copy constructor calls illegal?
  5. Date: 15 Mar 1996 15:13:40 GMT
  6. Organization: nasa
  7. Distribution: world
  8. Message-ID: <4ic1f4$a3p@reznor.larc.nasa.gov>
  9. References: <4i9tp8$fgt@reznor.larc.nasa.gov> <00001a81+0000ad4e@msn.com>
  10. NNTP-Posting-Host: jitter.larc.nasa.gov
  11.  
  12. In article <00001a81+0000ad4e@msn.com>, _GOYRA_@msn.com (David Byrden) writes:
  13. > >> When I try to do this (just trying to re-use code - it is there, why not?),
  14. > >> a new instance of the class is instantiated SOMEWHERE
  15. >     Well, you didn't post your code, but be advised that explicit ctor 
  16. > calls are not possible, no matter how much you would like to reuse 
  17. > the code. All ctor calls are associated with the creation of a fresh 
  18. > object. When you call the copy ctor, I guess you create a temporary 
  19. > object, whose lifetime does not extend beyond its own statement. 
  20. > Hence you should see the copy ctor and the dtor called for this 
  21. > temporary object.
  22. >                     David
  23.  
  24. David, 
  25.  
  26. Yes, you are so right!  I was incorrectly thinking of the Copy Constructor
  27. as just a Copy MAKER!  The construction that I was "missing" WAS being
  28. echoed to me when I confirmed entry into the CC with a cout.
  29.  
  30. By the way, an explicit call to the CC or any constructor IS possible, and
  31. is done routinely, just not the way I was trying to do it :)  I have used
  32. the copy constructor in lieu of an overloaded operator=, like
  33.        MyClass Myclass1;
  34.        int Myclass1.IMyClass(/*member values, etc. */);
  35.        MyClass Myclass2(Myclass1);  // Kind of an explicit CC call.
  36.  
  37. Thank you for slapping me back to reality.
  38.  
  39. Michael B. Lance
  40. Lockheed Engineering & Sciences
  41. Hampton, Virginia
  42.